﻿
//import Request from '../base/request.js'
const { createApp, ref, onMounted, h, reactive, toRefs, getCurrentInstance, toRaw, defineProps, defineEmits, unref, computed} = Vue;
function camelToHyphen(str) {
    // 将驼峰命名转换为连字符分隔的小写字符串
    return 'a-' + str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
function mcamelToHyphen(str) {
    // 将驼峰命名转换为连字符分隔的小写字符串
    return 'm-' + str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
const singalApp = (controllerName, manage, locale) => {

    // 定义 vue3 的对象
    const Composition ={
        setup() {
            var Params = {

            }
            console.log(getCurrentInstance(),'getCurrentInstance()')
            if (getCurrentInstance()) {
                const { proxy } = getCurrentInstance()
                Params[controllerName + 'Params'] = manage(proxy)
            } else {
                Params[controllerName + 'Params'] = manage()
            }

            const vlocale = locale

            onMounted(() => {
                if (Params[controllerName + 'Params'].init) {
                    Params[controllerName + 'Params'].init()
                }
            })

            for (let e in Params[controllerName + 'Params'].template) {
                let str = mcamelToHyphen(e)
          
                vapp.component(str, Params[controllerName + 'Params'].template[e]);
            }

            console.log(Params[controllerName + 'Params'].template, 'Params[controllerName ')
          
            return { // 返回对象给模板
                ...Params,
                vlocale
            }
        }
    }
    const vapp = createApp(Composition);
    for (let e in antd) {
        let str = camelToHyphen(e)
        vapp.component(str, antd[e]);
    }

    vapp.config.errorHandler = (err) => {
        console.log(err, 'err')
        /* 处理错误 */
    }
    vapp.mount(`#`+controllerName);
}

